#ifndef CP932_HEADER
#define CP932_HEADER

// this header needs
#include <stdio.h>
#include "../ARRAY.h"
#include "ASCII.h"
#include "UNICD.h"

// epik CP932 map table
// some important constants are defined here
#include "CP932_U_TB.h"

// Microsoft Windows Code Page 932
// japanese encodings are a mess to find information about conversion.
// I based these functions and tables on the information of these pages.
// https://www.haible.de/bruno/charsets/conversion-tables/Shift_JIS.html
// http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP932.TXT
// I am assuming the "CP932" encoding is the one from that CP932.TXT file.

// will represent an CP932 character as with
// an umax container (as there are 1-2 byte characters)
typedef umax cp932_int;

// Windows 932 is a character encoding that has japanese characters
// for me it is a mess as I don't read japanese.
#define INV_CP932_INT 0x80
#define INV_CP932_INT_STR "[INV_CP932_INT]"
#define INV_ENC_CP932_STR "[INV_ENC_CP932]"

// this encoding inherits the ASCII table characters

// table definitions
#define CP932_ASCII_INT_CTRL_CHARS_START  0x00
#define CP932_ASCII_INT_CTRL_CHARS_END    0x19
#define CP932_ASCII_INT_PRINT_CHARS_START 0x20
#define CP932_ASCII_INT_PRINT_CHARS_END   0x7F
#define CP932_ASCII_INT_COMMA             0x2C
#define CP932_ASCII_INT_NEWLN             0xA0
#define CP932_ASCII_INT_WHITESPACE_LENGTH 6
cp932_int * CP932_ASCII_INT_WHITESPACE = ASCII_INT_WHITESPACE;

#define CP932_ASCII_INT_NUMBER_BEGIN 0
#define CP932_ASCII_INT_NUMBER_HEX_UPPER_BEGIN 10
#define CP932_ASCII_INT_NUMBER_HEX_LOWER_BEGIN 16
#define CP932_ASCII_INT_NUMBER_PMDX_BEGIN 22
#define CP932_ASCII_INT_NUMBER_LENGTH 26
cp932_int * CP932_ASCII_INT_NUMBER = ASCII_INT_NUMBER;

// checking
byte check_cp932_int(cp932_int ch);
byte check_enc_cp932(void * src, umax ssize);
// get/write
cp932_int get_cp932_int(void * src, umax ssize);
void * write_enc_cp932(cp932_int ch, void * dest, umax dsize);
// printing
byte print_cp932_int(cp932_int ch);
byte print_enc_cp932(void * src, umax ssize);

// unicode conversion related

// checking
byte check_cp932_as_unicd(cp932_int ch);
bool check_unicd_as_cp932(unicd_int ch);
// getting
unicd_int get_cp932_as_unicd(cp932_int ch);
cp932_int get_unicd_as_cp932(unicd_int ch);

#include "CP932.c"

#endif // CP932_HEADER
